package com.shirley.netty.tcp.client;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.LineEncoder;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.logging.LoggingHandler;
import io.netty.util.CharsetUtil;

public class TcpClientChannel extends ChannelInitializer<SocketChannel> {
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        socketChannel
                .pipeline()
                .addLast(new LineBasedFrameDecoder(1024))
                .addLast(new StringDecoder())
                .addLast(new LoggingHandler())
                .addLast(new LineEncoder(CharsetUtil.UTF_8))
                .addLast(new TcpClientInputMsgHandler());


//                .addLast(new LengthFieldPrepender(4))
//                .addLast(new StringEncoder(CharsetUtil.UTF_8))
//                .addLast(new LengthFieldBasedFrameDecoder(1024, 0, 4, 0, 4))
//                .addLast(new StringDecoder())
//                .addLast(new TcpClientInputMsgHandler());

    }
}
